package com.service.impl;

import com.dao.UserDao;
import com.entity.User;
import com.service.Userservice;

public class UserServiceImpl implements Userservice {
    private UserDao userDao;

    //无参构造
    public UserServiceImpl() {
    }

    public UserServiceImpl(UserDao userDao) {
        this.userDao = userDao;
    }

    //测试index属性的构造方法1
    public UserServiceImpl(String name,String context){
       System.out.println("name1:"+name);
        System.out.println("context1:"+context);
    }
    //测试index属性的构造方法2
    public UserServiceImpl(Integer context,String name){
        System.out.println("context2:"+context);
        System.out.println("name2:"+name);
    }

   //用于dao属性赋值的构造方法
    public UserServiceImpl(UserDao userDao,String name) {
        this.userDao = userDao;
        System.out.println(name);
    }
    //不在使用set方法进行注入，使用构造方法进行注入
//    public UserDao getUserDao() {
//            return userDao;
//        }
//    public void setUserDao(UserDao userDao) {
//        this.userDao = userDao;
//    }

    @Override
    public boolean save(User user) {
        int i=1;
        if(i==0){
            throw new RuntimeException("============出现异常，保存失败===========");
        }
        return userDao.insert(user)>0;
    }
}
